export default{
    namespaced: true,
    state: {
        name:"product模块",
        products:[]
    },
    mutations:{
        // 设置产品数据
        SET_PRODUCT(state,payload){
            state.products=payload;
        },
        // 减少库存
        DECREASE_INVENTORY(state,payload){
            let target=state.products.find(item=>item.id==payload.id)
            target.inventory--
        },
        INVENTORY(state,payload){
            let target=state.products.find(item=>item.id==payload.id)
            target.inventory++
        }
    },
    actions:{
        FETCH_PRODUCT({commit}){
            fetch("http://chst.vip/data/index.json")
            .then(body=>body.json())
            .then(res=>{
                console.log(res)
                commit("SET_PRODUCT",res.data);
            })
        }
    },
    getters:{}, 
}